package glossos.parsing;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

public class CorpusReaderTestCase {

	CorpusReader corpusReader;
	
	@Before
	public void setUp() throws Exception {
		corpusReader = new CorpusReader(fakeIterator());
	}

	@Test
	public void testRead() throws Exception {
		assertThat((char)corpusReader.read(), is('a'));
		assertThat((char)corpusReader.read(), is('\n'));
		assertThat((char)corpusReader.read(), is('b'));
		assertThat((char)corpusReader.read(), is('.'));
		assertThat((char)corpusReader.read(), is('.'));
		assertThat((char)corpusReader.read(), is('.'));
		assertThat((char)corpusReader.read(), is('c'));
		assertThat((char)corpusReader.read(), is('d'));
		assertThat((char)corpusReader.read(), is('\t'));
	}

	private Iterator<Reader> fakeIterator(){
		List<Reader> readers = new ArrayList<Reader>();
		readers.add(new StringReader("a\nb"));
		readers.add(new StringReader(""));
		readers.add(new StringReader(""));
		readers.add(new StringReader("cd\t"));
		return readers.iterator();
	}
	
}
